﻿#ifndef THREAD_H
#define THREAD_H


#include <QMutex>
#include <QWaitCondition>
//#include"globalsignals.h"
#include "http.h"
//#include "systemresource.h"
extern HTTP http;
bool ZJXS2RotaryTable(QString serialnumber,QString &Identnumber,int *const Electricity);
bool TMC7RotaryTable(QString serialnumber,QString &Identnumber);
bool TCLC6RotaryTable(QString serialnumber,QString &Identnumber);
//bool TCLT6RotaryTable(QString serialnumber,QString &Identnumber,char *pwd);
//bool TCLR1RotaryTable(QString serialnumber,QString &Identnumber,char *pwd);
//bool TCL3ARotaryTable(QString serialnumber,QString &Identnumber,char *pwd);
//bool TCLC7RotaryTable(QString serialnumber,QString &Identnumber,char *pwd);
//void handleViewStatis(const int& result);
//void terminateProcessByPath(const QString& processPath);
//bool TCLS8RotaryTable(QString serialnumber,QString &Identnumber);
// 任务类型
class Task
{
public:

    QTimer* timer;
    int Indet;  //标识

    int Row;//行
    int Column;//列
    int AppointFirst;//优先口
    int serialportnum;//几号串口
    QString serialport;//系统几号串口

    QString UserID;//UserID
    QString Password;//Password

    QString StartTime;  //开始时间
    QString EndTime;  //结束时间
    QString ID;  //部门编号
    QString  Name;//名称

    QString vid;//vid
    QString pid;//pid
    QString serialnumber;//设备序列号
    QString manufacturer;//设备制造商 3
    QString model;//设备型号 4
    QString route;//位置路径
    QString Device;//盘符
    QString Identnumber;//标识号
public:
    Task();
    ~Task();
    void Execute(int index);
};

// 执行线程
class WorkThread : public QThread
{
    Q_OBJECT // Add Q_OBJECT macro here
public:
    WorkThread();
    WorkThread(class ThreadPool *parent);
    ~WorkThread();
protected:
    virtual void run();


private:
    //usb_listener *m_usb_listener;
    class ThreadPool *m_Pool;

    Qt::HANDLE m_Handle;
    Task *task;

};

// 线程池
class ThreadPool : public QObject
{
    Q_OBJECT
public:
    ThreadPool();
    explicit ThreadPool(int count, QObject *parent = nullptr);
    ~ThreadPool();

    void PushTask(int Indet);
    void PushTask(UploadInfo threadinfo);
    void PushTask(DeviceInforMation threadinfo);
    void PushTask(InterfaceMappingInfo threadinfo);
    void PushTask(LoginInfo threadinfo);
    void PushTask(WarnInstanInfo threadinfo);
    void Start(QString threadname);
    void Destroy();
    void a();
    //void RegisterDevice();
    void Threadincrease(int count, QObject *parent = nullptr);
private:

    QList<UploadInfo> U_Tasks;                             // 任务队列
    QList<int> M_Tasks;                             // 任务队列
    QList<DeviceInforMation> DIM_Tasks;                             // 任务队列
    QList<InterfaceMappingInfo> IM_Tasks;                             // 任务队列
    QList<LoginInfo> LI_Tasks;                             // 任务队列
    QList<WarnInstanInfo> WI_Tasks;                             // 任务队列
    QList<QSharedPointer<WorkThread>> m_Threads;      // 运行的线程
    bool m_bStop;                                    // 停止线程
    QString Name;

    QTimer* timer;
    QMutex m_TaskMutex;
    QWaitCondition m_NotEmpty;

    friend class WorkThread;
};
#endif // THREAD_H
